package com.sm.config;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatModels {

    @Value("${spring.ai.openai.api-key}")
    private String dashScopeApiKey;
    @Value("${spring.ai.openai.chat.options.model}")
    private String dashScopeModel;
    @Value("${spring.ai.openai.base-url}")
    private String dashScopeBaseUrl;


    @Value("${spring.ai.deepseek.api-key}")
    private String deepseekApiKey;
    @Value("${spring.ai.deepseek.base-url}")
    private String deepseekBaseUrl;
    @Value("${spring.ai.deepseek.chat.options.model}")
    private String deepseekModel;
    private final String QWEN_MODEL = "qwen-plus";
    @Bean(name = "deepseekChatModel")
    public ChatModel deepseekChatModel() {
        return DeepSeekChatModel.
                builder()
                .deepSeekApi(
                        DeepSeekApi
                                .builder()
                                .apiKey(deepseekApiKey)
                                .baseUrl(deepseekBaseUrl)
                                .build()
                        )
                .defaultOptions(
                        DeepSeekChatOptions.builder()
                                .model(deepseekModel)
                                .build()
                )
                .build();
    }

    @Bean(name = "alibabaChatModel")
    public ChatModel alibabaChatModel() {
        return OpenAiChatModel.builder()
                .openAiApi(
                        OpenAiApi.builder()
                                .apiKey(dashScopeApiKey)
                                .baseUrl(dashScopeBaseUrl)
                                .build()
                )
                .defaultOptions(
                        OpenAiChatOptions.builder()
                                .model(dashScopeModel)
                                .build()
                )
                .build();
    }
}
